<template>
	<om-page :title="pageTitle">
		<om-topbutton :hasBgColor="true" @click='searchTab'></om-topbutton>
		<view class="page__bd" style="margin-top:53px;">
			<uni-list>
				<uni-list-item :showArrow="false" >
					<view>
						<view>{{userInfo.userName}}</view>
					</view>
				</uni-list-item>
				<view v-for="(item, index) in datas" :key="index">
					<uni-list-item  @click="onClick(item)" :data-index="index" :extraText="(item.monthAttendDays?item.monthAttendDays:0) + '天'">
						<view class="flex">
							<view>{{item.attendYear + '-' + item.attendMonth}}</view>
							<om-dot :showDot="item.canConfirm"/>
						</view>
					</uni-list-item>
				</view>
			</uni-list>
		</view>
	</om-page>
</template>

<script>
	import listLoad from '../../../static/js/listLoad.js';
	import {getUrl } from '../../../static/js/common.js'
	import {
		mapState
	} from 'pinia';
	import {
		useLoginUserStore
	} from '@/stores/login-user.js';
export default {
	data() {
		return {
			id:"",
			datas: [],
			pageTitle:"",
			cachename:"workhour",
			userInfo:{
				userName:"",
				userId:"",
				sexCode:""
			}
		};
	},
	computed:{
		...mapState(useLoginUserStore, ['hasLogin', 'forcedLogin', 'userName','userId','avatar','sexCode'])
	},
	methods: {
		searchTab() {
			let param = {
					url:'attendMonth/findSearchUserPage',
					msg:"考勤与薪资核算业务主管可以查所有人；其他上级可查下级！",
					cachename:this.cachename
			}
			let url = getUrl('../search/search',param)
			uni.navigateTo({
				url: url
			});
		},
		loadData(userId) {
			let _that = this;
			
			_that.om.request(
			'wxAttend/getAttendMonthList',
			{
				userId:userId
			}
			).then(res => {
				if (res.succeed) {
					_that.datas = res.value;
				}
			});
		},
		getPageInfo(show, title, params) {
			uni.setStorage({
				key: 'info',
				data: show,
			})
			var url = './new-workhour-cache-info?cacheKey=info&title=' + title+'&attendYear='+params[0]+'&attendMonth='+params[1]+'&id='+params[2]+'&userId='+params[3]+'&sexCode='+params[4]
			uni.navigateTo({
				url: url
			})
		},
		onClick(item) {
			this.getPageInfo(item.attendMonthShow, '详细信息',[item.attendYear,item.attendMonth,item.id,this.userInfo.userId?this.userInfo.userId:this.userId,this.userInfo.sexCode?this.userInfo.sexCode:this.sexCode]);
		}
	},
	onLoad(options) {
		this.pageTitle =  options.title || '工时统计'
		uni.setNavigationBarTitle({
			title: this.pageTitle
		});
		this.userInfo.userName = this.userName
		this.userInfo.userId = this.userId
	},
	onShow() {
		uni.getStorage({
			key:this.cachename,
			success:(res)=>{
				if(res.data){
					let d = res.data
					this.userInfo.userName = d.username
					this.userInfo.userId = d.id
					this.userInfo.sexCode = d.sex
					this.loadData(d.id);
				}
			},
			fail:(res)=>{
				this.loadData(this.userId);
			}
		})
	},
	onUnload(){
			uni.removeStorage({
				key:this.cachename,
				success:(res)=>{}
			})
	}
};
</script>

<style scoped>
</style>
